<template>
	<view>
		<my-loading :vshow="loadingshow"></my-loading>
		
		<view class="uni-margin-wrap">
			<swiper class="swiper" circular indicator-dots="true" autoplay="true" interval="4000"
				duration="500">
				<swiper-item v-for="(item,k) in swiperImg" :key="k">				
					<view class="swiper-item">
						<image style="width: 100%;height: 100%;" :src="item.image" @click="preview(item.id)"></image>							
					</view>
				</swiper-item>
				
				
			</swiper>
		</view>
		<view class="tabs">
			<view class="tabs-left">
				<u-subsection 
					:list="stolist" 
					:current="current" 
					height="60" 
					bg-color="#656661"
					button-color="#848580"
					active-color="#fff"
					inactive-color="#fff"
					@change="sectionChange"
				>
				</u-subsection>
			</view>
			<view class="tabs-right" @click="gotoJion">
				<text>门店加盟</text>
			</view>
		</view>
		<view class="content" :style="{ 'background-image': 'url(' + bgimg + ')' }">
			<scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-Y" @scrolltoupper="upper"
								@scrolltolower="lower" @scroll="scroll">
				<view class="topselect" v-if="current == 1" @click="show = true">
					<view class="">
						省: {{province}}
					</view>
					<view class="">
						市: {{city}}
					</view>
				</view>
				<view class="content-list">
					<view class="empty" v-if="storeList == ''">
						<u-empty text="该地区没有门店" mode="list" color="#ffffff" icon-color="#ffffff"></u-empty>
						<view class="list-item" v-for="(item, k) in storermList" :key="k" :style="{ 'background-image': 'url(' + http + item.thumb + ')', 'background-size': '100% 100%'}">
							<view class="name">
								<view class="name-left" @click="clickStore(item.id)">
									{{item.name}}
								</view>
								<view class="name-right" @click="goserver(item.id)">
									<image src="../../static/goto2.png" mode=""></image>
								</view>
							</view>
							<view class="address" >
								<view class="address-left" @click="markertap(item.wd,item.jd)">
									<view class="addicon">
										<image src="../../static/map.png" mode=""></image>
									</view>
									<view class="addtext">
										{{item.address}}
									</view>
								</view>
								<view class="address-right" @click="freeTell(item.mobile)">
									<view class="">
										<u-icon name="phone"></u-icon>
									</view>
									<view class="">
										{{item.mobile}}
									</view>
								</view>
							</view>
						</view>
					</view>
					<view class="list-item" v-for="(item, k) in storeList" :key="k" :style="{ 'background-image': 'url(' + http + item.thumb + ')', 'background-size': '100% 100%'}">
						<view class="name">
							<view class="name-left" @click="clickStore(item.id)">
								{{item.name}}
							</view>
							<view class="name-right" @click="goserver(item.id)">
								<image src="../../static/goto3.png" mode=""></image>
							</view>
						</view>
						<view class="address" >
							<view class="address-left" @click="markertap(item.wd,item.jd)">
								<view class="addicon">
									<image src="../../static/map.png" mode=""></image>
								</view>
								<view class="addtext">
									{{item.address}}
								</view>
							</view>
							<view class="address-right" @click="freeTell(item.mobile)">
								<view class="">
									<u-icon name="phone"></u-icon>
								</view>
								<view class="">
									{{item.mobile}}
								</view>
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	
		<u-picker v-model="show" mode="region" :params="params" :area-code='["44", "4404"]' @confirm="areaConfirm"></u-picker>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userData: [],
				scrollTop: 0,
				old: {
					scrollTop: 0
				},
				loadingshow: false,
				navbackground: {
					backgroundColor: '#272228',
				},
				swiperImg: [],//轮播图列表
				current: 0,
				typeid: 1,
				stolist: [
					{
						name: '热门'
					}, 
					{
						name: '省市'
					}
				],
				bgimg: 'https://adjyxw.h1668.com/uploads/20231017/e0871278f83e67d70f73fe252047313a.jpg',
				storeList: [],
				storermList: [],
				show: false,
				params: {
					province: true,
					city: true,
					area: false
				},
				province: '广东省',
				provinceid: 44,
				city: '珠海市',
				cityid: 4404,
				http: 'https://adjyxw.h1668.com',
			};
		},
		onLoad() {
			this.getAdimageList()
			this.getStoreList(1)
			this.getAdList()
		},
		onShow() {
			this.userData = uni.getStorageSync('userData');
		},
		methods: {
			//门店加盟
			gotoJion() {
				uni.navigateTo({
					url: '/pagesB/server/join'
				})
			},
			//门店点击事件
			clickStore(id) {
				uni.request({
					url: uni.getStorageSync('URL') + 'home/Carpark/Carpark/xiugaiStore',
					method: 'POST',
					data: {
						stoid: id,
						busid: this.userData.id,
					},
					header: {
						"X-Requested-With": "XMLHttpRequest"
					},
					dataType: 'json',
					success: (res)=> {
						uni.switchTab({
							url: '/pages/serve/server'
						})
					}
				});
			},
			scroll: function(e) {
				this.old.scrollTop = e.detail.scrollTop
			},
			areaConfirm(e) {
				this.province = e.province.label
				this.provinceid = e.province.value
				this.city = e.city.label
				this.cityid = e.city.value
				this.getStoreList(0)
				this.getStorermList()
			},
			goserver(id) {
				uni.navigateTo({
					url: '/pagesB/server/server2?id=' +id
				})
			},
			//地址点击事件
			markertap(latitude,longitude) {
				uni.openLocation({
					latitude: parseFloat(latitude),
					longitude: parseFloat(longitude),
					scale: 18
				})
			},
			//拨打门店电话
			freeTell(mobile) {
				wx.makePhoneCall({
					phoneNumber: mobile, //仅为示例，并非真实的电话号码
					success: function() {
						console.log("拨打电话成功！")
					},
					fail: function() {
						console.log("拨打电话失败！")
					}
				})
			},
			sectionChange(index) {
				this.current = index;
				if(index == 0) {
					this.getStoreList(1)
				}else if(index == 1) {
					this.getStoreList(0)
				}
			},
			getStoreList(id) {
				this.loadingshow = true
				uni.request({
					url: uni.getStorageSync('URL') + 'home/Carpark/Carpark/storeList',
					method: 'POST',
					data: {
						typeid: id,
						province: this.provinceid,
						city: this.cityid
					},
					header: {
						"X-Requested-With": "XMLHttpRequest"
					},
					dataType: 'json',
					success: (res)=> {
						this.storeList = res.data.data
						this.loadingshow = false
					}
				});
			},
			getStorermList() {
				uni.request({
					url: uni.getStorageSync('URL') + 'home/Carpark/Carpark/storeList',
					method: 'POST',
					data: {
						typeid: 1,
					},
					header: {
						"X-Requested-With": "XMLHttpRequest"
					},
					dataType: 'json',
					success: (res)=> {
						this.storermList = res.data.data
					}
				});
			},
			getAdimageList() {
				uni.request({
					url: uni.getStorageSync('URL') + 'home/Carpark/Carpark/getstorelistimg',
					method: 'POST',
					header: {
						"X-Requested-With": "XMLHttpRequest"
					},
					dataType: 'json',
					success: (res)=> {
						this.bgimg = res.data.data.thumb
					}
				});
			},
			//获取广告图
			getAdList() {
				uni.request({
					url: uni.getStorageSync('URL') + 'home/Carpark/Carpark/gettopimglist',
					method: 'POST',
					header: {
						"X-Requested-With": "XMLHttpRequest"
					},
					dataType: 'json',
					success: (res)=> {
						this.swiperImg = res.data.data
					}
				});
			},
			preview(id) {
				let item = {
				    serverId: id,
					stoid: this.stoid,
				};
				uni.navigateTo({
					url: '/pagesB/server/serverDetail?item='+ encodeURIComponent(JSON.stringify(item))
				})
			},
		}
	}
</script>

<style lang="scss">
page{
	background-color: #6b6b6b;
}
.scroll-Y {
	height: 1000rpx;
}
.uni-margin-wrap {
	width: 100%;
	background-color: #fff;
	.swiper {
		height: 350rpx;
		.swiper-item {
			display: block;
			height: 350rpx;
			line-height: 350rpx;
			text-align: center;
		}
	}
}
.tabs {
	width: 97%;
	height: 60rpx;
	display: flex;
	margin: 15rpx auto;
	.tabs-left {
		width: 60%;
		height: 60rpx;
	}
	.tabs-right {
		width: 40%;
		height: 60rpx;
		line-height: 60rpx;
		text-align: right;
		font-size: 38rpx;
		color: #0baafb;
		font-weight: bold;
	}
}
.content {
	width: 97%;
	height: 1000rpx;
	margin: 15rpx auto;
	background-repeat: no-repeat;
	background-size: 100% 100%;
	.topselect {
		width: 100%;
		height: 60rpx;
		background-color: #6b6b6b;
		display: flex;
		justify-content: space-around;
		align-items: center;
		color: #fff;
		font-size: 1.1rem;
	}
	.content-list {
		width: 100%;
		height: 100%;
		.empty {
			
		}
		.list-item {
			width: 100%;
			height: 220rpx;
			color: #fff;
			.name {
				width: 100%;
				display: flex;
				// background-color: #888481;
				// opacity: 0.8;
				.name-left {
					width: 85%;
					height: 140rpx;
					line-height: 140rpx;
					padding-left: 30rpx;
					color: #fff;
					font-size: 40rpx;
				}
				.name-right {
					width: 15%;
					height: 140rpx;
					display: flex;
					image {
						margin-top: 30rpx;
						width: 100%;
						height: 60%;
						object-fit: contain;
					}
				}
			}
			.address {
				width: 100%;
				display: flex;
				letter-spacing: 1px;
				.address-left {
					width: 70%;
					height: 80rpx;
					display: flex;
					background-color: #687177;
					opacity: 0.8;
					.addicon {
						width: 15%;
						height: 80rpx;
						padding: 15rpx;
						image {
							width: 100%;
							height: 100%;
							object-fit: contain;
						}
					}
					.addtext {
						width: 85%;
						height: 80rpx;
						font-size: 0.8rem;
						display: flex;
						align-items: center;
					}
				}
				.address-right {
					width: 30%;
					height: 80rpx;
					background-color: #3d484a;
					text-align: center;
					opacity: 0.9;
				}
			}
		}
		.list-item:not(:first-child) {
		  margin-top: 10rpx;
		}
	}
}
</style>
